<template>
  <div>
    <div id="height" ref="height" style="width: 600px;height:400px;"></div>
  </div>
</template>

<script>
import echarts from 'echarts'
import {getHw} from "@/api/student-exam";

export default {
  data() {
    return {
      examVos: []
    }
  },
  methods: {
    getHeight(num) {
      getHw().then(res => {
        console.log(res.find(exam => exam.academicYear == num).height ? res.find(exam => exam.academicYear == num).height : 0)
        return res.find(exam => exam.academicYear == num).height || 0
      }).catch(err => {
      })
    }
  },
  mounted() {
    const heightChart = echarts.init(document.getElementById('height'));
    const option = {
      title: {
        text: '身高变化图',
        left: 'center', // 居中对齐
      },
      tooltip: {
        trigger: 'axis'
      },
      xAxis: {
        type: 'category',
        data: ['第一学年', '第二学年', '第三学年', '第四学年']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [this.getHeight(1), this.getHeight(2), this.getHeight(3), this.getHeight(4)],
          type: 'line',
          smooth: true,
          label: { // 设置每个点显示数据
            show: true
          }
        }
      ]
    };
    heightChart.setOption(option)
  },
}
</script>

<style scoped>

</style>
